package com.ffcs.cn.action.labelBase.workspace;

import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.desktop.controls.ui.controls.SmFileChoose;
import com.supermap.desktop.core.Application;
import com.supermap.desktop.core.FileChooseMode;
import com.supermap.desktop.core.Interface.IBaseItem;
import com.supermap.desktop.core.enums.OpenWorkspaceResult;
import com.supermap.desktop.core.implement.CtrlAction;
import com.supermap.desktop.core.utilties.WorkspaceUtilities;
import com.ffcs.cn.DevelopProperties;

import javax.swing.*;

/**
 * 打开工作空间
 *
  */
public class CtrlActionOpenWorkspace extends CtrlAction {
	public CtrlActionOpenWorkspace(IBaseItem caller) {
		super(caller);
	}

	@Override
	protected void run() {
		SmFileChoose workspaceChooser = new SmFileChoose("OpenWorkspace", FileChooseMode.OPEN_ONE)
				.setTitle(DevelopProperties.getString("String_OpenWorkspace"))
				.addFileFilter(DevelopProperties.getString("String_FileFilters_Workspace"), "smwu", "sxwu");
		if (workspaceChooser.showDefaultDialog() == JFileChooser.APPROVE_OPTION && !"".equals(workspaceChooser.getSelectedFile().getAbsolutePath())) {
			// 创建一个工作空间连接信息
			WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(workspaceChooser.getFilePath());
			// 打开工作空间
			OpenWorkspaceResult result = WorkspaceUtilities.openWorkspace(info, true);
			if (result == OpenWorkspaceResult.SUCCESSED) {
				Application.getActiveApplication().getMainFrame().getFormManager().closeAll();
			}
		}
	}
}
